package com.ruoyi.web.controller.wx;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.service.IByBsTimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/wx/bstime")
@Validated
public class WxBsTimeController {

    @Autowired
    IByBsTimeService bsTimeService;

    @PostMapping("getDateJSON")
    public Object getDateJSON(){
        JSONObject datejson = bsTimeService.getDateAndNextDate();
        return AjaxResult.success(datejson);
    }

    @PostMapping("inBsTimeData")
    public Object inBsTimeData(@RequestBody String param){
        // System.out.println(param);
        JSONObject json = JSONObject.parseObject(param);
        String userid = json.getString("userid");
        // ---------------------------通过userid获取帮手id--------------------------
        // ---------------------------进行帮手的基础数据添加-----------------------------------
        bsTimeService.bsInDateData(userid);

        return AjaxResult.success();
    }

    @PostMapping("updateBsTimestatus")
    public Object updateBsTimestatus(@RequestBody String param){
        JSONObject json = JSONObject.parseObject(param);
        bsTimeService.updateBsTimestatus(json);
        return AjaxResult.success();
    }


    @PostMapping("showBsTimeDataForDate")
    public Object showBsTimeDataForDate(@RequestBody String param){
        JSONObject json = JSONObject.parseObject(param);
        List<JSONObject> list = bsTimeService.showBsTimeDataForDate(json);
        return AjaxResult.success(list);
    }
}
